package com.gwt.auth.feign;

import com.gwt.auth.params.TokenForm;
import com.gwt.auth.vo.AuthTokenVO;
import com.gwt.cloud.result.ApiResult;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

@FeignClient(name = "gwt-auth-server", contextId = "authFeign", path = "/auth/user", fallback = AuthFeignFallBack.class)
public interface AuthFeign {

    @ApiOperation(value = "创建token",notes = "创建token")
    @PostMapping("/token/create")
    ApiResult<AuthTokenVO> tokenCreate(@RequestParam TokenForm form);

    @ApiOperation(value = "token认证",notes = "token认证")
    @PostMapping("/token/validate")
    ApiResult<AuthTokenVO> tokenValidate();

    @ApiOperation(value = "token刷新",notes = "token刷新(一般不主动刷新)")
    @PostMapping("/token/refresh")
    ApiResult<AuthTokenVO> tokenRefresh(@RequestParam TokenForm form);

    @ApiOperation(value = "token清理",notes = "token清理（退出登陆）")
    @PostMapping("/token/clean")
    ApiResult tokenClean();
}
class AuthFeignFallBack implements AuthFeign {

    private static final String MSG = "网络繁忙，请稍后再试!";

    @Override
    public ApiResult<AuthTokenVO> tokenCreate(TokenForm form) {
        return ApiResult.error(MSG);
    }

    @Override
    public ApiResult<AuthTokenVO> tokenValidate() {
        return ApiResult.error(MSG);
    }

    @Override
    public ApiResult<AuthTokenVO> tokenRefresh(TokenForm form) {
        return ApiResult.error(MSG);
    }

    @Override
    public ApiResult tokenClean() {
        return ApiResult.error(MSG);
    }
}